package com.sikaryofficial.backend.controller.music;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.domain.dto.req.music.MusicLibraryListReq;
import com.sikaryofficial.backend.domain.dto.req.music.MusicLibraryReq;
import com.sikaryofficial.backend.domain.dto.resp.music.MusicLibraryDTO;
import com.sikaryofficial.backend.manager.information.MusicLibraryManager;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.common.log.annotation.Log;
import com.sikaryofficial.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 音乐Controller
 *
 * @author qinjinyuan
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/musicLibrary/backend")
@Api(tags = "V3.5.1-音乐库后台管理")
@Slf4j
public class MusicLibraryBackendController extends BaseController {
    @Autowired
    private MusicLibraryManager musicLibraryManager;
    /**
     * 查询音乐库分页列表
     */
    @PostMapping("/listPage")
    @ApiOperation("查询音乐库分页列表")
    public PageResult<MusicLibraryDTO> listPage(@Validated @RequestBody MusicLibraryListReq req) {
        // 查询获奖列表
        IPage<MusicLibraryDTO> page = musicLibraryManager.listPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 音乐详细信息
     */
    @GetMapping(value = "/detail/{musicId}")
    @ApiOperation("音乐详细信息")
    public R<MusicLibraryDTO> getInfo(@PathVariable("musicId") Long musicId) {
        return R.ok(musicLibraryManager.getInfo(musicId));
    }

    /**
     * 音乐库新增或修改
     */
    @Log(title = "音乐库", businessType = BusinessType.INSERT)
    @PostMapping(value = "/saveOrUpdate")
    @ApiOperation("音乐库新增或修改")
    public R<Long> saveOrUpdate(@Validated @RequestBody MusicLibraryReq req) {
        return R.ok(musicLibraryManager.saveOrUpdate(req));
    }

    /**
     * 删除音乐库
     */
    @Log(title = "音乐库", businessType = BusinessType.DELETE)
    @GetMapping(value = "/remove/{musicIds}")
    @ApiOperation("删除音乐库")
    public R<Boolean> remove(
            @ApiParam(value = "musicIds，支持一个或多个,英文逗号分隔", required = true)
            @PathVariable String musicIds) {
        musicLibraryManager.remove(musicIds);
        return R.ok(Boolean.TRUE);
    }
}
